#define L_VERSION   1111225
#include <llib.h>

using namespace llib;
using namespace llib::geom;

#define QUITE

class TransplantSimulator : public Simulator {
private:
    static const Int32 elementNum = 6;
    static const Int32 colorNum = 8;
    static const Int32 elemPerAxis = 7;

    const Float spacing;

public:
    TransplantSimulator() : spacing(4.f) {}

    virtual Boolean Render()
    {
        Vec3f elemColor;
        Float colorInterval = 1.f / (elemPerAxis - 1);
        GLfloat x_start, y_start, z_start;
        GLfloat x_pos, y_pos, z_pos;
        x_start = y_start = z_start = -((elemPerAxis - 1) * spacing / 2.0f);
        x_pos = y_pos = z_pos = -((elemPerAxis - 1) * spacing / 2.0f);

        glTranslatef(x_start, y_start, z_start);
        FOR(x,0,elemPerAxis) {
            elemColor.x = Float(colorInterval * x);
            FOR(y,0,elemPerAxis) {
                elemColor.y = Float(colorInterval * y);
                FOR(z,0,elemPerAxis) {
                    elemColor.z = Float(colorInterval * z);
                    glColor3fv(elemColor.cell);
                    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, elemColor.cell);
                    glutSolidCube(1);

                    //z += spacing;
                    glTranslatef(0.f, 0.f, spacing);
                }
                //z_pos = z_start;
                //y_pos += spacing;
                glTranslatef(0.f, 0.f, -spacing * elemPerAxis);
                glTranslatef(0.f, spacing, 0.f);
            }
            //y_pos = y_start;
            //x_pos += spacing;
            glTranslatef(0.f, -spacing * elemPerAxis, 0.f);
            glTranslatef(spacing, 0.f, 0.f);
        }

        return TRUE;
    }

#ifndef QUITE
    virtual Boolean OnMouseButtonDown(Uint8 button, Int32 x, Int32 y)
    {
        cout << "OnMouseButtonDown -> [button=" << (Int32)button << ", x=" << x << ", y=" << y << "]" << endl;
        return TRUE;
    }

    virtual Boolean OnMouseButtonUp(Uint8 button, Int32 x, Int32 y)
    {
        cout << "OnMouseButtonUp -> [button=" << (Int32)button << ", x=" << x << ", y=" << y << "]" << endl;
        return TRUE;
    }

    virtual Boolean OnMouseMove(Uint8 button, Int32 x, Int32 y)
    {
        cout << "OnMouseMove -> [button=" << (Int32)button << ", x=" << x << ", y=" << y << "]" << endl;
        return TRUE;
    }

    virtual Boolean OnMouseWheel(Uint8 wheel, Int32 x, Int32 y)
    {
        cout << "OnMouseWheel -> [wheel=" << (Int32)wheel << ", x=" << x << ", y=" << y << "]" << endl;
        return TRUE;
    }
#endif
};












Int32 main(Int32 argc, Char **argv)
{
    AppFramework.SetSimulator(new Navigator(new TransplantSimulator()));
    AppFramework.SetWindowTitle("Transplant Simulator");
    AppFramework.SetFullScreen(FALSE);
    AppFramework.FrameworkMain(argc, argv);
    return 0;
}
